package com.jn.erp.wechat.staff.handler;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.jn.erp.common.utils.DateUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * <pre>
 *  小程序信息相关
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/9/25 14:05
 */
//@AllArgsConstructor
@Component
public class MiniappMessageHandler {

    private final WxMaService wxMaService;


    @Autowired
    public MiniappMessageHandler(@Qualifier("teacherWxMaService") WxMaService wxMaService){
        this.wxMaService = wxMaService;
    }

    //想用户发送日程提醒
    public Boolean sendSubscribeMsg() {
        try {
            List<WxMaSubscribeMessage.MsgData> data =
            Arrays.asList(                                                //"2024/09/25 14:35:06"
                            new WxMaSubscribeMessage.MsgData("time1", DateUtils.dateTimeNow("yyyy/MM/dd HH:mm:ss")),
                            new WxMaSubscribeMessage.MsgData("thing3", "日程地点：这里看你"+ DateUtils.getDate()),
                            new WxMaSubscribeMessage.MsgData("thing4", "日程备注：备注消息"),
                            new WxMaSubscribeMessage.MsgData("thing6", "日程事项：发送消息"),
                            new WxMaSubscribeMessage.MsgData("thing8", "姓名：    丫爱丫")
                    );

            WxMaSubscribeMessage subscribeMessage = WxMaSubscribeMessage.builder()
                    .templateId("b2W0lYbrtw-twq_w840tFZOezSzV6MmGRFZLwjMu_sw")
                    .data(data)
                    .toUser("oYL9_7c83MsgeRg1lbTS3DqPfpeI")
                    .build();
            wxMaService.getMsgService().sendSubscribeMsg(subscribeMessage);
            return true;
        } catch (WxErrorException e) {
            System.out.println(e.getError());
            return false;
        }
    }


}
